﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MachineQA.Model;
using MachineQA.DataAccess;

namespace MachineQA.Tests.Mocks
{
    public class MockLocationRepository : ILocationRepository
    {
        readonly List<Location> _locations;

        public event EventHandler<LocationAddedOrRemovedEventArgs> LocationAddedOrRemoved;

        public MockLocationRepository(List<Location> locations)
        {
            _locations = new List<Location>(locations);
        }

        #region Public Interface
        
        public void AddLocation(Location location)
        {
            if (!_locations.Contains(location))
            {
                _locations.Add(location);
                if (this.LocationAddedOrRemoved != null)
                    this.LocationAddedOrRemoved(this, new LocationAddedOrRemovedEventArgs(location, true));
            }
        }

        public void RemoveLocation(Location location)
        {
            if (_locations.Contains(location))
            {
                _locations.Remove(location);
                if (this.LocationAddedOrRemoved != null)
                    this.LocationAddedOrRemoved(this, new LocationAddedOrRemovedEventArgs(location, false));
            }
        }

        public List<Model.Location> GetLocations()
        {
            return _locations;
        }

        public bool ContainsLocation(Model.Location location)
        {
            return _locations.Contains(location);
        }

        #endregion
    }
}
